{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "74daa3e2",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'yishu'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[13], line 7\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[0;32m      6\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mnp\u001b[39;00m\n\u001b[1;32m----> 7\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01myishu\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdatasets\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[0;32m      8\u001b[0m WarningType\u001b[38;5;241m.\u001b[39mShowWarning \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'yishu'"
     ]
    }
   ],
   "source": [
    "from pyecharts.charts import *\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.commons.utils import JsCode\n",
    "from pyecharts.globals import WarningType\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from yishu.datasets import *\n",
    "WarningType.ShowWarning = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4e16aa6a",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "(unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \\UXXXXXXXX escape (143896730.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[1], line 1\u001b[1;36m\u001b[0m\n\u001b[1;33m    pd.read_csv('C:\\Users\\17329\\Desktop\\python数据分析\\tianchi_mobile_recommend_train_user.csv')\u001b[0m\n\u001b[1;37m                                                                                           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \\UXXXXXXXX escape\n"
     ]
    }
   ],
   "source": [
    "pd.read_csv('C:\\Users\\17329\\Desktop\\python数据分析\\tianchi_mobile_recommend_train_user.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4476a537",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'pd' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[2], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mpd\u001b[49m\u001b[38;5;241m.\u001b[39mread_csv(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mC:/Users/17329/Desktop/python数据分析/tianchi_mobile_recommend_train_user.csv\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'pd' is not defined"
     ]
    }
   ],
   "source": [
    "pd.read_csv('C:/Users/17329/Desktop/python数据分析/tianchi_mobile_recommend_train_user.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3b106fc7",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'pd' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[3], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m df \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241m.\u001b[39mread_csv(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mC:/Users/17329/Desktop/python数据分析/tianchi_mobile_recommend_train_user.csv\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m      2\u001b[0m df[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdate\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mto_datetime(df[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtime\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mstr\u001b[38;5;241m.\u001b[39mslice(stop\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m10\u001b[39m))\n\u001b[0;32m      3\u001b[0m df\u001b[38;5;241m.\u001b[39mhead()\n",
      "\u001b[1;31mNameError\u001b[0m: name 'pd' is not defined"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv('C:/Users/17329/Desktop/python数据分析/tianchi_mobile_recommend_train_user.csv')\n",
    "df[\"date\"] = pd.to_datetime(df[\"time\"].str.slice(stop=10))\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "09311f83",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import *\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.commons.utils import JsCode\n",
    "from pyecharts.globals import WarningType\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "dd1c9438",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>item_id</th>\n",
       "      <th>behavior_type</th>\n",
       "      <th>user_geohash</th>\n",
       "      <th>item_category</th>\n",
       "      <th>time</th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>98047837</td>\n",
       "      <td>232431562</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4245</td>\n",
       "      <td>2014-12-06 02</td>\n",
       "      <td>2014-12-06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>97726136</td>\n",
       "      <td>383583590</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5894</td>\n",
       "      <td>2014-12-09 20</td>\n",
       "      <td>2014-12-09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>98607707</td>\n",
       "      <td>64749712</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2883</td>\n",
       "      <td>2014-12-18 11</td>\n",
       "      <td>2014-12-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>98662432</td>\n",
       "      <td>320593836</td>\n",
       "      <td>1</td>\n",
       "      <td>96nn52n</td>\n",
       "      <td>6562</td>\n",
       "      <td>2014-12-06 10</td>\n",
       "      <td>2014-12-06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>98145908</td>\n",
       "      <td>290208520</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>13926</td>\n",
       "      <td>2014-12-16 21</td>\n",
       "      <td>2014-12-16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    user_id    item_id  behavior_type user_geohash  item_category  \\\n",
       "0  98047837  232431562              1          NaN           4245   \n",
       "1  97726136  383583590              1          NaN           5894   \n",
       "2  98607707   64749712              1          NaN           2883   \n",
       "3  98662432  320593836              1      96nn52n           6562   \n",
       "4  98145908  290208520              1          NaN          13926   \n",
       "\n",
       "            time       date  \n",
       "0  2014-12-06 02 2014-12-06  \n",
       "1  2014-12-09 20 2014-12-09  \n",
       "2  2014-12-18 11 2014-12-18  \n",
       "3  2014-12-06 10 2014-12-06  \n",
       "4  2014-12-16 21 2014-12-16  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('C:/Users/17329/Desktop/python数据分析/tianchi_mobile_recommend_train_user.csv')\n",
    "df[\"date\"] = pd.to_datetime(df[\"time\"].str.slice(stop=10))\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "17b9774c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id\n",
       "1    738\n",
       "2    673\n",
       "3    636\n",
       "4    573\n",
       "5    498\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_freq = df[df[\"behavior_type\"] == 4].groupby(\"user_id\")[\"user_id\"].count()\n",
    "user_freq_count = user_freq.value_counts().sort_index()\n",
    "user_freq_count.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ddfa900a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/v5/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"0a9387fdb6994f8aab7e0236941225af\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_0a9387fdb6994f8aab7e0236941225af = echarts.init(\n",
       "                    document.getElementById('0a9387fdb6994f8aab7e0236941225af'), 'white', {renderer: 'canvas'});\n",
       "                var option_0a9387fdb6994f8aab7e0236941225af = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"color\": [\n",
       "        \"#5470c6\",\n",
       "        \"#91cc75\",\n",
       "        \"#fac858\",\n",
       "        \"#ee6666\",\n",
       "        \"#73c0de\",\n",
       "        \"#3ba272\",\n",
       "        \"#fc8452\",\n",
       "        \"#9a60b4\",\n",
       "        \"#ea7ccc\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                738,\n",
       "                673,\n",
       "                636,\n",
       "                573,\n",
       "                498,\n",
       "                481,\n",
       "                460,\n",
       "                429,\n",
       "                359,\n",
       "                363,\n",
       "                313,\n",
       "                261,\n",
       "                257,\n",
       "                196,\n",
       "                213,\n",
       "                170,\n",
       "                177,\n",
       "                144,\n",
       "                130,\n",
       "                111,\n",
       "                127,\n",
       "                92,\n",
       "                110,\n",
       "                99,\n",
       "                84,\n",
       "                79,\n",
       "                59,\n",
       "                63,\n",
       "                59,\n",
       "                50,\n",
       "                48,\n",
       "                41,\n",
       "                49,\n",
       "                40,\n",
       "                33,\n",
       "                45,\n",
       "                31,\n",
       "                39,\n",
       "                26,\n",
       "                25,\n",
       "                25,\n",
       "                18,\n",
       "                33,\n",
       "                29,\n",
       "                23,\n",
       "                16,\n",
       "                17,\n",
       "                20,\n",
       "                22,\n",
       "                15,\n",
       "                16,\n",
       "                10,\n",
       "                13,\n",
       "                13,\n",
       "                14,\n",
       "                16,\n",
       "                12,\n",
       "                11,\n",
       "                11,\n",
       "                7,\n",
       "                12,\n",
       "                4,\n",
       "                7,\n",
       "                4,\n",
       "                9,\n",
       "                9,\n",
       "                6,\n",
       "                5,\n",
       "                6,\n",
       "                3,\n",
       "                3,\n",
       "                9,\n",
       "                2,\n",
       "                2,\n",
       "                2,\n",
       "                2,\n",
       "                2,\n",
       "                2,\n",
       "                5,\n",
       "                1,\n",
       "                1,\n",
       "                2,\n",
       "                1,\n",
       "                1,\n",
       "                3,\n",
       "                1,\n",
       "                1,\n",
       "                3,\n",
       "                3,\n",
       "                2,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                2,\n",
       "                1,\n",
       "                1,\n",
       "                4,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                1,\n",
       "                2,\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                1,\n",
       "                2,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                2,\n",
       "                2,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                1,\n",
       "                1\n",
       "            ],\n",
       "            \"realtimeSort\": false,\n",
       "            \"showBackground\": false,\n",
       "            \"stackStrategy\": \"samesign\",\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1,\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23,\n",
       "                24,\n",
       "                25,\n",
       "                26,\n",
       "                27,\n",
       "                28,\n",
       "                29,\n",
       "                30,\n",
       "                31,\n",
       "                32,\n",
       "                33,\n",
       "                34,\n",
       "                35,\n",
       "                36,\n",
       "                37,\n",
       "                38,\n",
       "                39,\n",
       "                40,\n",
       "                41,\n",
       "                42,\n",
       "                43,\n",
       "                44,\n",
       "                45,\n",
       "                46,\n",
       "                47,\n",
       "                48,\n",
       "                49,\n",
       "                50,\n",
       "                51,\n",
       "                52,\n",
       "                53,\n",
       "                54,\n",
       "                55,\n",
       "                56,\n",
       "                57,\n",
       "                58,\n",
       "                59,\n",
       "                60,\n",
       "                61,\n",
       "                62,\n",
       "                63,\n",
       "                64,\n",
       "                65,\n",
       "                66,\n",
       "                67,\n",
       "                68,\n",
       "                69,\n",
       "                70,\n",
       "                71,\n",
       "                72,\n",
       "                73,\n",
       "                75,\n",
       "                76,\n",
       "                77,\n",
       "                78,\n",
       "                79,\n",
       "                81,\n",
       "                82,\n",
       "                83,\n",
       "                84,\n",
       "                85,\n",
       "                86,\n",
       "                87,\n",
       "                88,\n",
       "                91,\n",
       "                92,\n",
       "                93,\n",
       "                94,\n",
       "                95,\n",
       "                96,\n",
       "                97,\n",
       "                98,\n",
       "                99,\n",
       "                100,\n",
       "                101,\n",
       "                103,\n",
       "                104,\n",
       "                106,\n",
       "                107,\n",
       "                108,\n",
       "                109,\n",
       "                110,\n",
       "                113,\n",
       "                115,\n",
       "                116,\n",
       "                117,\n",
       "                122,\n",
       "                125,\n",
       "                126,\n",
       "                127,\n",
       "                128,\n",
       "                130,\n",
       "                137,\n",
       "                142,\n",
       "                145,\n",
       "                149,\n",
       "                151,\n",
       "                167,\n",
       "                168,\n",
       "                225,\n",
       "                242,\n",
       "                251,\n",
       "                441,\n",
       "                649,\n",
       "                809\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"name\": \"\\u7528\\u6237\\u8d2d\\u4e70\\u9891\\u6b21\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ],\n",
       "    \"dataZoom\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"slider\",\n",
       "        \"showDetail\": true,\n",
       "        \"showDataShadow\": true,\n",
       "        \"realtime\": true,\n",
       "        \"start\": 0,\n",
       "        \"end\": 100,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"zoomLock\": false,\n",
       "        \"filterMode\": \"filter\"\n",
       "    }\n",
       "};\n",
       "                chart_0a9387fdb6994f8aab7e0236941225af.setOption(option_0a9387fdb6994f8aab7e0236941225af);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x1872f85be90>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar = Bar()\n",
    "bar.add_xaxis(user_freq_count.index.tolist())\n",
    "bar.add_yaxis(\"\", user_freq_count.values.tolist(), label_opts=opts.LabelOpts(is_show=False))\n",
    "bar.set_global_opts(\n",
    "    yaxis_opts=opts.AxisOpts(name='用户购买频次', type_=\"value\"),\n",
    "    datazoom_opts=opts.DataZoomOpts(range_start=0, range_end=100, orient='horizontal')\n",
    ")\n",
    "bar.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8cafe8ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date\n",
       "1    14027\n",
       "2     7421\n",
       "3     4849\n",
       "4     3377\n",
       "5     2465\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_lag = df[df[\"behavior_type\"] == 4].groupby('user_id')[\"date\"].apply(lambda x:x.sort_values().diff(1).dropna().dt.days)\n",
    "user_lag_count = user_lag.value_counts().sort_index()[1:]\n",
    "user_lag_count.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a0914947",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/v5/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"49d2a0a48c814689b9632930d2b8a614\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_49d2a0a48c814689b9632930d2b8a614 = echarts.init(\n",
       "                    document.getElementById('49d2a0a48c814689b9632930d2b8a614'), 'white', {renderer: 'canvas'});\n",
       "                var option_49d2a0a48c814689b9632930d2b8a614 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"color\": [\n",
       "        \"#5470c6\",\n",
       "        \"#91cc75\",\n",
       "        \"#fac858\",\n",
       "        \"#ee6666\",\n",
       "        \"#73c0de\",\n",
       "        \"#3ba272\",\n",
       "        \"#fc8452\",\n",
       "        \"#9a60b4\",\n",
       "        \"#ea7ccc\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                14027,\n",
       "                7421,\n",
       "                4849,\n",
       "                3377,\n",
       "                2465,\n",
       "                1813,\n",
       "                1296,\n",
       "                1015,\n",
       "                769,\n",
       "                603,\n",
       "                477,\n",
       "                400,\n",
       "                350,\n",
       "                283,\n",
       "                227,\n",
       "                201,\n",
       "                128,\n",
       "                122,\n",
       "                117,\n",
       "                90,\n",
       "                72,\n",
       "                57,\n",
       "                59,\n",
       "                26,\n",
       "                20,\n",
       "                24,\n",
       "                12,\n",
       "                7,\n",
       "                7,\n",
       "                1\n",
       "            ],\n",
       "            \"realtimeSort\": false,\n",
       "            \"showBackground\": false,\n",
       "            \"stackStrategy\": \"samesign\",\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1,\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23,\n",
       "                24,\n",
       "                25,\n",
       "                26,\n",
       "                27,\n",
       "                28,\n",
       "                29,\n",
       "                30\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"name\": \"\\u7528\\u6237\\u8d2d\\u4e70\\u95f4\\u9694\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ],\n",
       "    \"dataZoom\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"slider\",\n",
       "        \"showDetail\": true,\n",
       "        \"showDataShadow\": true,\n",
       "        \"realtime\": true,\n",
       "        \"start\": 0,\n",
       "        \"end\": 100,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"zoomLock\": false,\n",
       "        \"filterMode\": \"filter\"\n",
       "    }\n",
       "};\n",
       "                chart_49d2a0a48c814689b9632930d2b8a614.setOption(option_49d2a0a48c814689b9632930d2b8a614);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x187282ae650>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar = Bar()\n",
    "bar.add_xaxis(user_lag_count.index.tolist())\n",
    "bar.add_yaxis(\"\", user_lag_count.values.tolist(), label_opts=opts.LabelOpts(is_show=False))\n",
    "bar.set_global_opts(\n",
    "    yaxis_opts=opts.AxisOpts(name='用户购买间隔', type_=\"value\"),\n",
    "    datazoom_opts=opts.DataZoomOpts(range_start=0, range_end=100, orient='horizontal')\n",
    ")\n",
    "bar.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c8e055d7",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Cannot subset columns with a tuple with more than one element. Use a list instead.",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[10], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m user_unique_item \u001b[38;5;241m=\u001b[39m \u001b[43mdf\u001b[49m\u001b[43m[\u001b[49m\u001b[43mdf\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mbehavior_type\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m==\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m4\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgroupby\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43muser_id\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mitem_id\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mitem_category\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241m.\u001b[39mnunique()\n\u001b[0;32m      2\u001b[0m user_unique_item_count \u001b[38;5;241m=\u001b[39m user_unique_item[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mitem_id\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mvalue_counts()\u001b[38;5;241m.\u001b[39msort_index()\n\u001b[0;32m      3\u001b[0m user_unique_item_category_count \u001b[38;5;241m=\u001b[39m user_unique_item[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mitem_category\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mvalue_counts()\u001b[38;5;241m.\u001b[39msort_index()\n",
      "File \u001b[1;32mF:\\aconda\\Lib\\site-packages\\pandas\\core\\groupby\\generic.py:1767\u001b[0m, in \u001b[0;36mDataFrameGroupBy.__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   1763\u001b[0m \u001b[38;5;66;03m# per GH 23566\u001b[39;00m\n\u001b[0;32m   1764\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(key, \u001b[38;5;28mtuple\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(key) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[0;32m   1765\u001b[0m     \u001b[38;5;66;03m# if len == 1, then it becomes a SeriesGroupBy and this is actually\u001b[39;00m\n\u001b[0;32m   1766\u001b[0m     \u001b[38;5;66;03m# valid syntax, so don't raise\u001b[39;00m\n\u001b[1;32m-> 1767\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[0;32m   1768\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCannot subset columns with a tuple with more than one element. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1769\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUse a list instead.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1770\u001b[0m     )\n\u001b[0;32m   1771\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39m\u001b[38;5;21m__getitem__\u001b[39m(key)\n",
      "\u001b[1;31mValueError\u001b[0m: Cannot subset columns with a tuple with more than one element. Use a list instead."
     ]
    }
   ],
   "source": [
    "user_unique_item = df[df[\"behavior_type\"] == 4].groupby(\"user_id\")[\"item_id\",\"item_category\"].nunique()\n",
    "user_unique_item_count = user_unique_item[\"item_id\"].value_counts().sort_index()\n",
    "user_unique_item_category_count = user_unique_item[\"item_category\"].value_counts().sort_index()\n",
    "user_unique_count = pd.DataFrame({\"item_count\" : user_unique_item_count, \"item_category_count\" : user_unique_item_category_count})\n",
    "user_unique_count.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "6df06233",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>item_count</th>\n",
       "      <th>item_category_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>779.0</td>\n",
       "      <td>841.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>736.0</td>\n",
       "      <td>813.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>687.0</td>\n",
       "      <td>770.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>620.0</td>\n",
       "      <td>699.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>548.0</td>\n",
       "      <td>659.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   item_count  item_category_count\n",
       "1       779.0                841.0\n",
       "2       736.0                813.0\n",
       "3       687.0                770.0\n",
       "4       620.0                699.0\n",
       "5       548.0                659.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_unique_item = df[df[\"behavior_type\"] == 4].groupby(\"user_id\")[[\"item_id\",\"item_category\"]].nunique()\n",
    "user_unique_item_count = user_unique_item[\"item_id\"].value_counts().sort_index()\n",
    "user_unique_item_category_count = user_unique_item[\"item_category\"].value_counts().sort_index()\n",
    "user_unique_count = pd.DataFrame({\"item_count\" : user_unique_item_count, \"item_category_count\" : user_unique_item_category_count})\n",
    "user_unique_count.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0681a469",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/v5/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"915bcd90d7784c85b4d77a7f81298d55\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_915bcd90d7784c85b4d77a7f81298d55 = echarts.init(\n",
       "                    document.getElementById('915bcd90d7784c85b4d77a7f81298d55'), 'white', {renderer: 'canvas'});\n",
       "                var option_915bcd90d7784c85b4d77a7f81298d55 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"aria\": {\n",
       "        \"enabled\": false\n",
       "    },\n",
       "    \"color\": [\n",
       "        \"#5470c6\",\n",
       "        \"#91cc75\",\n",
       "        \"#fac858\",\n",
       "        \"#ee6666\",\n",
       "        \"#73c0de\",\n",
       "        \"#3ba272\",\n",
       "        \"#fc8452\",\n",
       "        \"#9a60b4\",\n",
       "        \"#ea7ccc\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u7528\\u6237\\u8d2d\\u4e70\\u7684\\u4e0d\\u540c\\u5546\\u54c1\\u6570\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                779.0,\n",
       "                736.0,\n",
       "                687.0,\n",
       "                620.0,\n",
       "                548.0,\n",
       "                546.0,\n",
       "                490.0,\n",
       "                465.0,\n",
       "                397.0,\n",
       "                348.0,\n",
       "                326.0,\n",
       "                285.0,\n",
       "                222.0,\n",
       "                225.0,\n",
       "                188.0,\n",
       "                161.0,\n",
       "                135.0,\n",
       "                138.0,\n",
       "                127.0,\n",
       "                125.0,\n",
       "                104.0,\n",
       "                91.0,\n",
       "                99.0,\n",
       "                66.0,\n",
       "                64.0,\n",
       "                67.0,\n",
       "                57.0,\n",
       "                49.0,\n",
       "                52.0,\n",
       "                44.0,\n",
       "                45.0,\n",
       "                45.0,\n",
       "                34.0,\n",
       "                34.0,\n",
       "                23.0,\n",
       "                25.0,\n",
       "                39.0,\n",
       "                18.0,\n",
       "                25.0,\n",
       "                30.0,\n",
       "                25.0,\n",
       "                18.0,\n",
       "                19.0,\n",
       "                21.0,\n",
       "                15.0,\n",
       "                14.0,\n",
       "                22.0,\n",
       "                16.0,\n",
       "                14.0,\n",
       "                9.0,\n",
       "                9.0,\n",
       "                14.0,\n",
       "                9.0,\n",
       "                7.0,\n",
       "                5.0,\n",
       "                7.0,\n",
       "                7.0,\n",
       "                8.0,\n",
       "                5.0,\n",
       "                3.0,\n",
       "                1.0,\n",
       "                3.0,\n",
       "                4.0,\n",
       "                1.0,\n",
       "                3.0,\n",
       "                3.0,\n",
       "                1.0,\n",
       "                2.0,\n",
       "                4.0,\n",
       "                2.0,\n",
       "                2.0,\n",
       "                3.0,\n",
       "                3.0,\n",
       "                5.0,\n",
       "                1.0,\n",
       "                2.0,\n",
       "                2.0,\n",
       "                1.0,\n",
       "                2.0,\n",
       "                null,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                2.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                3.0,\n",
       "                null,\n",
       "                2.0,\n",
       "                1.0,\n",
       "                3.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                2.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                null,\n",
       "                1.0,\n",
       "                null,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                1.0\n",
       "            ],\n",
       "            \"realtimeSort\": false,\n",
       "            \"showBackground\": false,\n",
       "            \"stackStrategy\": \"samesign\",\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u7528\\u6237\\u8d2d\\u4e70\\u7684\\u4e0d\\u540c\\u5546\\u54c1\\u7c7b\\u522b\\u6570\",\n",
       "            \"legendHoverLink\": true,\n",
       "            \"data\": [\n",
       "                841.0,\n",
       "                813.0,\n",
       "                770.0,\n",
       "                699.0,\n",
       "                659.0,\n",
       "                643.0,\n",
       "                538.0,\n",
       "                500.0,\n",
       "                431.0,\n",
       "                354.0,\n",
       "                316.0,\n",
       "                272.0,\n",
       "                209.0,\n",
       "                188.0,\n",
       "                156.0,\n",
       "                174.0,\n",
       "                163.0,\n",
       "                132.0,\n",
       "                102.0,\n",
       "                92.0,\n",
       "                76.0,\n",
       "                82.0,\n",
       "                50.0,\n",
       "                67.0,\n",
       "                54.0,\n",
       "                47.0,\n",
       "                47.0,\n",
       "                41.0,\n",
       "                35.0,\n",
       "                36.0,\n",
       "                32.0,\n",
       "                21.0,\n",
       "                32.0,\n",
       "                20.0,\n",
       "                23.0,\n",
       "                19.0,\n",
       "                10.0,\n",
       "                10.0,\n",
       "                13.0,\n",
       "                11.0,\n",
       "                13.0,\n",
       "                9.0,\n",
       "                4.0,\n",
       "                8.0,\n",
       "                5.0,\n",
       "                8.0,\n",
       "                2.0,\n",
       "                8.0,\n",
       "                4.0,\n",
       "                3.0,\n",
       "                3.0,\n",
       "                6.0,\n",
       "                2.0,\n",
       "                null,\n",
       "                3.0,\n",
       "                null,\n",
       "                2.0,\n",
       "                1.0,\n",
       "                null,\n",
       "                2.0,\n",
       "                5.0,\n",
       "                3.0,\n",
       "                null,\n",
       "                null,\n",
       "                3.0,\n",
       "                1.0,\n",
       "                1.0,\n",
       "                null,\n",
       "                1.0,\n",
       "                null,\n",
       "                null,\n",
       "                1.0,\n",
       "                null,\n",
       "                2.0,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                2.0,\n",
       "                2.0,\n",
       "                null,\n",
       "                null,\n",
       "                1.0,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                1.0,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                1.0,\n",
       "                null,\n",
       "                1.0,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null,\n",
       "                null\n",
       "            ],\n",
       "            \"realtimeSort\": false,\n",
       "            \"showBackground\": false,\n",
       "            \"stackStrategy\": \"samesign\",\n",
       "            \"cursor\": \"pointer\",\n",
       "            \"barMinHeight\": 0,\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"barGap\": \"30%\",\n",
       "            \"large\": false,\n",
       "            \"largeThreshold\": 400,\n",
       "            \"seriesLayoutBy\": \"column\",\n",
       "            \"datasetIndex\": 0,\n",
       "            \"clip\": true,\n",
       "            \"zlevel\": 0,\n",
       "            \"z\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u7528\\u6237\\u8d2d\\u4e70\\u7684\\u4e0d\\u540c\\u5546\\u54c1\\u6570\",\n",
       "                \"\\u7528\\u6237\\u8d2d\\u4e70\\u7684\\u4e0d\\u540c\\u5546\\u54c1\\u7c7b\\u522b\\u6570\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14,\n",
       "            \"backgroundColor\": \"transparent\",\n",
       "            \"borderColor\": \"#ccc\",\n",
       "            \"borderWidth\": 1,\n",
       "            \"borderRadius\": 0,\n",
       "            \"pageButtonItemGap\": 5,\n",
       "            \"pageButtonPosition\": \"end\",\n",
       "            \"pageFormatter\": \"{current}/{total}\",\n",
       "            \"pageIconColor\": \"#2f4554\",\n",
       "            \"pageIconInactiveColor\": \"#aaa\",\n",
       "            \"pageIconSize\": 15,\n",
       "            \"animationDurationUpdate\": 800,\n",
       "            \"selector\": false,\n",
       "            \"selectorPosition\": \"auto\",\n",
       "            \"selectorItemGap\": 7,\n",
       "            \"selectorButtonGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"enterable\": false,\n",
       "        \"confine\": false,\n",
       "        \"appendToBody\": false,\n",
       "        \"transitionDuration\": 0.4,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5,\n",
       "        \"order\": \"seriesAsc\"\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                1,\n",
       "                2,\n",
       "                3,\n",
       "                4,\n",
       "                5,\n",
       "                6,\n",
       "                7,\n",
       "                8,\n",
       "                9,\n",
       "                10,\n",
       "                11,\n",
       "                12,\n",
       "                13,\n",
       "                14,\n",
       "                15,\n",
       "                16,\n",
       "                17,\n",
       "                18,\n",
       "                19,\n",
       "                20,\n",
       "                21,\n",
       "                22,\n",
       "                23,\n",
       "                24,\n",
       "                25,\n",
       "                26,\n",
       "                27,\n",
       "                28,\n",
       "                29,\n",
       "                30,\n",
       "                31,\n",
       "                32,\n",
       "                33,\n",
       "                34,\n",
       "                35,\n",
       "                36,\n",
       "                37,\n",
       "                38,\n",
       "                39,\n",
       "                40,\n",
       "                41,\n",
       "                42,\n",
       "                43,\n",
       "                44,\n",
       "                45,\n",
       "                46,\n",
       "                47,\n",
       "                48,\n",
       "                49,\n",
       "                50,\n",
       "                51,\n",
       "                52,\n",
       "                53,\n",
       "                54,\n",
       "                55,\n",
       "                56,\n",
       "                57,\n",
       "                58,\n",
       "                59,\n",
       "                60,\n",
       "                61,\n",
       "                62,\n",
       "                63,\n",
       "                64,\n",
       "                65,\n",
       "                66,\n",
       "                67,\n",
       "                68,\n",
       "                69,\n",
       "                71,\n",
       "                72,\n",
       "                73,\n",
       "                75,\n",
       "                77,\n",
       "                78,\n",
       "                79,\n",
       "                80,\n",
       "                81,\n",
       "                82,\n",
       "                83,\n",
       "                84,\n",
       "                85,\n",
       "                86,\n",
       "                87,\n",
       "                89,\n",
       "                90,\n",
       "                92,\n",
       "                93,\n",
       "                94,\n",
       "                95,\n",
       "                96,\n",
       "                98,\n",
       "                101,\n",
       "                102,\n",
       "                106,\n",
       "                110,\n",
       "                111,\n",
       "                112,\n",
       "                114,\n",
       "                115,\n",
       "                125,\n",
       "                134,\n",
       "                135,\n",
       "                139,\n",
       "                140,\n",
       "                159,\n",
       "                182,\n",
       "                232,\n",
       "                235,\n",
       "                299,\n",
       "                545\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"type\": \"value\",\n",
       "            \"name\": \"\\u5546\\u54c1\\uff08\\u7c7b\\u522b\\uff09\\u6570\",\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": true,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"target\": \"blank\",\n",
       "            \"subtarget\": \"blank\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"textAlign\": \"auto\",\n",
       "            \"textVerticalAlign\": \"auto\",\n",
       "            \"triggerEvent\": false\n",
       "        }\n",
       "    ],\n",
       "    \"dataZoom\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"slider\",\n",
       "        \"showDetail\": true,\n",
       "        \"showDataShadow\": true,\n",
       "        \"realtime\": true,\n",
       "        \"start\": 0,\n",
       "        \"end\": 30,\n",
       "        \"orient\": \"horizontal\",\n",
       "        \"zoomLock\": false,\n",
       "        \"filterMode\": \"filter\"\n",
       "    }\n",
       "};\n",
       "                chart_915bcd90d7784c85b4d77a7f81298d55.setOption(option_915bcd90d7784c85b4d77a7f81298d55);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x1871b8f8f50>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar = Bar()\n",
    "bar.add_xaxis(user_unique_count.index.tolist())\n",
    "bar.add_yaxis(\"用户购买的不同商品数\", user_unique_count[\"item_count\"].values.tolist(), label_opts=opts.LabelOpts(is_show=False))\n",
    "bar.add_yaxis(\"用户购买的不同商品类别数\", user_unique_count[\"item_category_count\"].values.tolist(), label_opts=opts.LabelOpts(is_show=False))\n",
    "bar.set_global_opts(\n",
    "    yaxis_opts=opts.AxisOpts(name='商品（类别）数', type_=\"value\"),\n",
    "    datazoom_opts=opts.DataZoomOpts(range_start=0, range_end=30, orient='horizontal')\n",
    ")\n",
    "bar.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a1d01bb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
